<template>
    <div class="flex-wrap mb-2">
      <el-space wrap :size="10" class="">
        <el-input
          v-model="params.win_name"
          style="width: 150px"
          placeholder="用户名称"
        />
        <el-button :icon="Search" plain @click="search">查詢</el-button>
      </el-space>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="fb_user_id" label="User ID" />
      <el-table-column prop="win_name" label="用户名称" />
      <el-table-column prop="status" label="状态" />
      <el-table-column prop="remarks" label="备注" />
      <el-table-column fixed="right" label="操作" width="100">
        <template #default="scope">
          <el-space direction="vertical">
            <el-button
              link
              size="small"
              type="danger"
              @click="handleEdit(scope.$index, scope.row)"
              >删除</el-button
            >
          </el-space>
        </template>
      </el-table-column>
    </el-table>
    <div v-if="total > params.page_size" class="mt-2 flex justify-center">
      <el-pagination
        v-model:current-page="params.current_page"
        v-model:page-size="params.page_size"
        :page-sizes="[10, 20, 30, 40]"
        :small="false"
        :disabled="false"
        :background="true"
        layout="total, sizes, prev, pager, next"
        :total="Number(total)"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
</template>
<script lang="ts" setup>
import { ref, onMounted, watch, computed } from "vue";
import { Search, PriceTag, ArrowDown } from "@element-plus/icons-vue";
import { $getBlack } from "@api/market";
import { useI18n } from "vue-i18n";
import { useLocaleStore } from "@/store/locales";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
const { t } = useI18n();
const langkey = computed(() => useLocale.locale);
const useLocale = useLocaleStore();
let params = ref({
  current_page: 1,
  page_size: 10,
  win_name:""
});
const total = ref(0);
const tableData = ref([]);
onMounted(() => {
  getData();
});
const getData = async () => {
  let res = await $getBlack(params.value);
  console.log(res);
  if (res.code == 0) {
    tableData.value = res.data.table;
    total.value = res.data.total;
  }
};
const handleSizeChange = (val: number) => {
  params.value.page_size = val;
  getData();
};
const handleCurrentChange = (val: number) => {
  params.value.current_page = val;
  getData();
  console.log(`current page: ${val}`);
};
const search = () => {
  console.log(params.value);
  getData();
};
const handleEdit = (index: number, row: any) => {
  console.log(val);
};
</script>

<style lang="scss" scoped></style>
@/api/live
